/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package presenter;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import model.MetodoIMCInfantil;
import view.CalculoIMCInfantilView;

/**
 *
 * @author jakson
 */
public class CalculoIMCInfantilPresenter {

    private CalculoIMCInfantilView view;
    private MetodoIMCInfantil imcInfantil = new MetodoIMCInfantil();
    int idade = 0;
    char sexo = 0;
    double peso = 0;
    double altura = 0;

    public CalculoIMCInfantilPresenter() {
        view = new CalculoIMCInfantilView(null, true);
 

        view.getBtnCalcular().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                calculaImcInfantil();
            }
        });
        
        view.getBtnCancelar().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
               view.dispose();
            }
        });
        
        view.setLocationRelativeTo(view);
        view.setVisible(true);

    }

    public void calculaImcInfantil() {
        idade = Integer.parseInt(view.getComboBoxIdade().getSelectedItem().toString());
        sexo = view.getComboBoxSexo().getSelectedItem().toString().charAt(0);
        peso = Double.parseDouble(view.getCampoPeso().getText());
        altura = Double.parseDouble(view.getCampoAltura().getText());
        imcInfantil.fazerCalculo(peso, altura);
        imcInfantil.classificar(idade, sexo);
        double imcPessoa = imcInfantil.getImc();
        DecimalFormat fmt = new DecimalFormat("0.00");   //limita o número de casas decimais      
        String string = fmt.format(imcPessoa);
        view.getLabelImc().setText(string);
        view.getLabelCalssifi().setText(imcInfantil.getCondicao());
    }
}
